<template>
    <!-- 应急管理-应急预案管理 -->
    <div class="empReward">
        <div class="top">
            <div class="search">
                <div class="list">
                    <DatePicker type="daterange" :clearable="false" placeholder="开始时间   -   结束时间" style="width: 200px"
                        v-model="value" @on-change="getTime"></DatePicker>
                </div>
                <div class="list">
                    <Input placeholder="搜索编号/事件名称" style="width:150px" v-model="keyword" clearable />
                    <input type="password" autocomplete="new-password" style="display: none" />
                </div>
                <input type="text" class="intBox" style="display:none" />
                <div class="list" @click="onSerch">
                    <Button type="primary">搜索</Button>
                </div>
                <div class="list" @click="onReset">
                    <Button>重置</Button>
                </div>
            </div>
            <div class="down">
                <el-button type="primary" @click="updateRow(0)" size="small" plain
                    :disabled="!btnList.includes('emp/reward/add')"> 新增应急预案</el-button>
                <el-button type="primary" size="small" plain> 刷 新</el-button>
            </div>
        </div>
        <div class="bottom">
            <div class="table">
                <el-table :data="list" :height="tableHeight" :stripe="true" style="width: 100%">
                    <el-table-column prop="val1" label="事件编号" ></el-table-column>
                    <el-table-column prop="val2" label="事件名称" ></el-table-column>
                    <el-table-column prop="val3" label="处理流程" >
                        <template slot-scope="scope">
                            <el-link v-if="scope.row.val3" target="_blank" :href="scope.row.val3" type="primary" >处理流程文件</el-link>
                            <el-link v-else type="info" :underline="false" >附件</el-link>
                        </template>
                    </el-table-column>
                    <el-table-column prop="val4" label="责任人" width="100"></el-table-column>
                    <el-table-column prop="val5" label="联系方式" width="120"></el-table-column>
                    <el-table-column prop="val6" label="创建时间" ></el-table-column>
                    <el-table-column prop="val7" label="最近修改人" width="100"></el-table-column>
                    <el-table-column prop="val8" label="最近修改时间" ></el-table-column>

                    <el-table-column label="操作" align="center" fixed="right" min-width="120">
                        <template slot-scope="scope">
                            <el-button type="text" size="small">查看</el-button>
                            <el-button type="text" size="small">编辑</el-button>
                            <el-button type="text" size="small">审核</el-button>
                            <el-button type="text" size="small">提交更新</el-button>
                        </template>
                    </el-table-column>
                </el-table>
            </div>
            <div class="clearfix"  >
                <div class="float-right">
                    <Page v-if="totalCount" style="margin: 20px 0;text-align: center;" :current.sync="current"
                        :total="totalCount" :page-size="pageSize" show-elevator show-total show-sizer
                        @on-change="pageChange" @on-page-size-change="pageSizeChange">
                    </Page>
                </div>
            </div>
        </div>

        <Modal v-model="deleteModal" title="删除" width="360px;" :mask-closable="false">
            <div style="margin:10px">确定要删除这条数据吗？</div>
            <div slot="footer">
                <el-button @click="cancel(2)" type="info" size="small" plain>取消</el-button>
                <el-button @click="detele" type="primary" size="small" plain v-preventReClick="1500">确定</el-button>
            </div>
        </Modal>

        <Modal v-model="updateModal" title="添加应急预案" width="520px" :mask-closable="false">
            <!-- <div class="item">
                <span class="tip">*</span>
                <span>人员:</span>
                <Select v-model="empId" style="width:300px" placeholder="请选择人员" :filterable="true"
                    @on-change="getEmpType">
                    <Option v-for="item in empList" :value="item.empId" :key="item.empId">{{ item.empName }}</Option>
                </Select>
            </div>
            <div class="item">
                <span class="tip">*</span>
                <span>发生时间:</span>
                <DatePicker type="date" v-model="date" placeholder="请选择发生时间" style="width: 300px" @on-change="getDate">
                </DatePicker>
            </div>
            <div class="item">
                <span>奖惩类型:</span>
                <div class="radio">
                    <el-radio-group v-model="radio">
                        <el-radio :label="1">奖励</el-radio>
                        <el-radio :label="2">惩罚</el-radio>
                    </el-radio-group>
                </div>
            </div>
            <div class="item">
                <span class="tip">*</span>
                <span>奖惩分类:</span>
                <Select v-model="itemId" style="width:300px" placeholder="请选择奖惩分类" :filterable="true">
                    <Option v-for="item in itemList" :value="item.code" :key="item.code">{{ item.name }}</Option>
                </Select>
            </div>
            <div class="item">
                <span class="tip">*</span>
                <span>描述:</span>
                <Input v-model="description" type="textarea" placeholder="请输入描述内容" :maxlength="200" style="width: 300px"
                    show-word-limit />
            </div> -->

            <div class="item">
                <span class="tip">*</span>
                <span>事件编号:</span>
                <Input v-model="description1" type="text" placeholder="请输入事件编号" :maxlength="200" style="width: 300px"
                    show-word-limit />
            </div>
            <div class="item">
                <span class="tip">*</span>
                <span>事件名称:</span>
                <Input v-model="description2" type="text" placeholder="请输入事件名称" :maxlength="200" style="width: 300px"
                    show-word-limit />
            </div>
            <div class="item">
                <span class="tip">*</span>
                <span>处理流程:</span>
                <el-upload class="upload-demo" action="https://jsonplaceholder.typicode.com/posts/" style="width: 300px"
                    :on-preview="handlePreview" :on-remove="handleRemove" :before-remove="beforeRemove" multiple
                    :limit="3" :on-exceed="handleExceed" :file-list="fileList">
                    <el-button size="small" type="primary">点击上传</el-button>
                    <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div>
                </el-upload>
            </div>
            <div class="item">
                <span class="tip">*</span>
                <span>责任人:</span>
                <Select v-model="empId" style="width:300px" placeholder="请选择责任人" :filterable="true"
                    @on-change="getEmpType">
                    <Option v-for="item in empList" :value="item.empId" :key="item.empId">{{ item.empName }}</Option>
                </Select>
            </div>
            <div class="item">
                <span class="tip">*</span>
                <span>联系方式:</span>
                <Input v-model="description3" type="text" placeholder="请输入联系方式" :maxlength="11" style="width: 300px" show-word-limit />
            </div>
            <div slot="footer">
                <el-button @click="cancel(1)" type="info" size="small" plain>取消</el-button>
                <el-button @click="submitAll" type="primary" size="small" plain v-preventReClick="1500">确定</el-button>
            </div>
        </Modal>
    </div>
</template>

<script>
    import {
        getEmpRewardList,
        getEmpRewardAdd,
        getEmpRewardDel,
        getAllPersonnelList,
        getSelectValue
    } from "@/api/api.js";
    export default {
        data() {
            return {
                current: 1,
                pageSize: 10,
                pageNum: 1,
                totalCount: "",
                corpType: "",
                projectId: "",
                keyword: "",
                list: [
                    {val1: 'bj159753', val2: '现场工人受伤', val3: 'https://zhgd01.ct10.cc/ms/dev/documentManage/file/2025092509145360958.pdf', val4: '曹溪身', val5: '18088888888', val6: '2025-09-20 12:00:00', val7: '曹溪身', val8: '2025-09-21 12:00:00', },
                    {val1: 'bj159753', val2: '现场工人受伤', val3: 'https://zhgd01.ct10.cc/ms/dev/documentManage/file/2025092509145360958.pdf', val4: '曹溪身', val5: '18088888888', val6: '2025-09-20 12:00:00', val7: '曹溪身', val8: '2025-09-21 12:00:00', },
                    {val1: 'bj159753', val2: '现场工人受伤', val3: 'https://zhgd01.ct10.cc/ms/dev/documentManage/file/2025092509145360958.pdf', val4: '曹溪身', val5: '18088888888', val6: '2025-09-20 12:00:00', val7: '曹溪身', val8: '2025-09-21 12:00:00', },
                    {val1: 'bj159753', val2: '现场工人受伤', val3: 'https://zhgd01.ct10.cc/ms/dev/documentManage/file/2025092509145360958.pdf', val4: '曹溪身', val5: '18088888888', val6: '2025-09-20 12:00:00', val7: '曹溪身', val8: '2025-09-21 12:00:00', },
                ],
                corpList: [],
                updateModal: false,
                isAdd: true,
                removeId: "",
                deleteModal: false,
                btnList: [],
                deptName: "",
                startDate: "",
                endDate: "",
                value: [],
                empList: [],
                empId: "",
                empName: "",
                date: "",
                tableHeight: window.innerHeight - 355,
                itemList: [], //改动 下拉值
                itemId: "",
                radio: "",
                description: "",
                labelByValue: {},
                fileList: [],
                description1: "",
                description2: "",
                description3: "",
            };
        },
        computed: {
            porjectObject() {
                return this.$store.state.porjectObject;
            }
        },
        watch: {
            porjectObject(val, oldVal) {
                if (val.deptId != oldVal.deptId) {
                    this.projectId = val.deptId;
                    this.deptName = val.name;
                    this.pageNum = 1;
                    this.current = 1;
                    this.keyword = "";
                    this.value = [];
                    this.getAllList();
                    this.getEmpList();
                }
            }
        },

        created() {
            this.selectValue(); //改动 初次加载下拉数据
        },
        mounted() {
            this.projectId = this.$store.state.porjectObject.deptId;
            this.deptName = this.$store.state.porjectObject.name;
            this.getAllList();
            this.getEmpList();
            this.btnList = JSON.parse(localStorage.getItem("arr"));
        },
        methods: {
            handleRemove(file, fileList) {
                console.log(file, fileList);
            },
            handlePreview(file) {
                console.log(file);
            },
            handleExceed(files, fileList) {
                this.$message.warning(
                    `当前限制选择 3 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`);
            },
            beforeRemove(file, fileList) {
                return this.$confirm(`确定移除 ${ file.name }？`);
            },
            //获取所有人员
            getEmpList() {
                let params = {
                    deptId: this.projectId
                };
                getAllPersonnelList(params)
                    .then(res => {
                        if (res.code == 200) {
                            this.empList = res.data.list;
                        } else {
                            this.$Message.warning(res.msg);
                        }
                    })
                    .catch(error => {
                        console.log(error);
                    });
            },
            getAllList() {
                let params = {
                    pageSize: this.pageSize,
                    pageNum: this.pageNum,
                    keyword: this.keyword,
                    projectId: this.projectId,
                    startDate: this.startDate,
                    endDate: this.endDate
                };
                /* getEmpRewardList(params)
                    .then(res => {
                        if (res.code == 200) {
                            this.list = res.data.list;
                            this.totalCount = res.data.total;
                        } else {
                            this.$Message.warning(res.msg);
                        }
                    })
                    .catch(error => {
                        console.log(error);
                    }); */
            },
            getTime(value) {
                this.startDate = value[0];
                this.endDate = value[1];
                // this.pageNum = 1;
                // this.current = 1;
                // this.getAllList();
            },
            // onSearch() {
            //     this.pageNum = 1;
            //     this.current = 1;
            //     this.getAllList();
            // },

            onSerch() {
                this.pageNum = 1;
                this.current = 1;
                this.getAllList();
            },
            onReset() {
                this.value = []
                this.startDate = null
                this.endDate = null
                this.keyword = null
                this.pageNum = 1;
                this.current = 1;
                this.getAllList();
            },
            pageChange(index) {
                this.pageNum = index;
                this.getAllList();
            },
            pageSizeChange(index) {
                this.pageSize = index;
                this.getAllList();
            },
            updateRow() {
                this.updateModal = true;
                this.empId = "";
                this.empName = "";
                this.date = "";
                this.radio = 1;
                this.itemId = "";
                this.description = "";
            },
            getEmpType(index) {
                this.empId = index;
                this.empList.forEach(i => {
                    if (index == i.empId) {
                        this.empName = i.empName;
                    }
                });
            },
            getDate(value) {
                this.date = value;
            },
            submitAll() {
                /* if (this.empId == "") {
                    this.$Modal.warning({
                        title: "您有必填字段",
                        content: "请选择人员"
                    });
                    return;
                }
                if (this.date == "") {
                    this.$Modal.warning({
                        title: "您有必填字段",
                        content: "请选择发生时间"
                    });
                    return;
                }
                if (this.itemId == "") {
                    this.$Modal.warning({
                        title: "您有必填字段",
                        content: "请选择奖惩分类"
                    });
                    return;
                }
                if (this.description == "") {
                    this.$Modal.warning({
                        title: "您有必填字段",
                        content: "请输入描述"
                    });
                    return;
                }
                let params = {
                    empId: this.empId,
                    empName: this.empName,
                    type: this.radio,
                    item: this.itemId,
                    description: this.description,
                    date: this.date
                };
                getEmpRewardAdd(params)
                    .then(res => {
                        if (res.code == 200) {
                            this.$Message.success("操作成功");
                            this.updateModal = false;
                            this.getAllList();
                        } else {
                            this.$Message.warning(res.msg);
                        }
                    })
                    .catch(error => {
                        console.log(error);
                    }); */
                this.updateModal = false;
            },
            remove(index, rows) {
                this.removeId = rows[index].id;
                this.deleteModal = true;
            },
            detele() {
                getEmpRewardDel(this.removeId)
                    .then(res => {
                        if (res.code == 200) {
                            this.$Message.success("操作成功");
                            this.getAllList();
                            this.deleteModal = false;
                        } else {
                            this.$Message.warning(res.msg);
                        }
                    })
                    .catch(error => {
                        console.log(error);
                    });
            },

            cancel(type) {
                if (type == 1) {
                    this.updateModal = false;
                } else if (type == 2) {
                    this.deleteModal = false;
                }
            },
            //改动
            selectValue() {
                let params = {
                    code: "reward_type"
                };
                const _this = this;
                getSelectValue(params)
                    .then(res => {
                        if (res.code == 200) {
                            this.itemList = res.data.childList;
                            let province_list = {};
                            for (let i = 0; i < this.itemList.length; i++) {
                                province_list[this.itemList[i].code] = this.itemList[i].name;
                            }
                            this.labelByValue = province_list;
                        }
                    })
                    .catch(error => {
                        console.log(error);
                    });
            },
        },
    };
</script>

<style scoped lang="less">
    // @import "./../../assets/style/emp_common.less";
    @import "./../../assets/style/themeBase.less";

    .empReward {
        width: 100%;
        height: 100%;
        padding: 10px;
        box-sizing: border-box;
        background: #f5f5f5;

        .top {
            width: 100%;
            height: 72px;
            background: #fff;
            border-radius: 10px;
            display: flex;
            justify-content: space-between;
            align-items: center;

            .search {
                width: auto;
                margin-left: 20px;
                padding-top: 20px;
                display: flex;
                justify-content: flex-start;
                align-items: center;

                .list {
                    display: flex;
                    justify-content: flex-start;
                    align-items: center;
                    padding-bottom: 20px;
                    margin-right: 20px;

                    span {
                        width: 70px;
                    }
                }
            }

            .down {
                width: auto;
                margin-right: 20px;
            }
        }

        .bottom {
            width: 100%;
            padding: 20px;
            margin-top: 10px;
            box-sizing: border-box;
            height: calc(100% - 82px);
            background: #fff;
            border-radius: 10px;

            .down {
                width: 98%;
                margin: 0 auto;
                margin-top: 20px;
            }

            .msg {
                margin-bottom: 20px;
                display: flex;
                flex-wrap: wrap;

                .list {
                    display: flex;
                    justify-content: flex-start;
                    align-items: center;
                    margin-right: 24px;

                    p {
                        margin-right: 10px;
                        font-size: 16px;
                        color: #000;

                        &:nth-child(2) {
                            color: red;
                        }
                    }
                }
            }

            .updateCorp {
                cursor: pointer;
                margin-left: 5px;
                padding: 2px 4px;
                font-size: 12px;
                font-weight: 400;
                line-height: 1;
                color: #ffffff;
                border-radius: 3px;
                background-color: var(--themeColor);
            }
        }
    }

    .item {
        width: 400px;
        display: flex;
        margin: 0 auto;
        justify-content: space-between;
        align-items: center;
        margin-top: 10px;
        position: relative;
        margin-bottom: 20px;
        padding-left: 16px;
        box-sizing: border-box;

        .radio {
            width: 300px;
            display: flex;
            justify-content: center;
        }

        .tip {
            position: absolute;
            top: 8px;
            left: 0;
            color: red;
            font-size: 16px;
        }
    }

    // /deep/.ivu-icon-ios-close{
    //     color: #fff;
    //     &:hover{
    //         color: #fff;
    //     }
    // }



    /deep/.ivu-input-group {
        border-radius: 20px;
    }

    /deep/.ivu-input-group .ivu-input {
        border-radius: 20px 0 0 20px;
        border-color: #EBF2F8;
        background: #EBF2F8;
    }

    /deep/.ivu-input-group-append {
        border-radius: 0 20px 20px 0;
    }

    /deep/.el-tag.el-tag--success {
        background-color: #E7F8F2;
        border-color: #28D79C;
        color: #3FCF77;
    }

    /deep/.el-tag {
        border-radius: 2px;
    }

    /deep/.ivu-select-selection {
        border-radius: 2px;
    }

    /deep/.el-tag.el-tag--info {
        background-color: rgba(255, 72, 72, 0.1);
        border-radius: 2px;
        border-color: #FF4848;
        color: #FF4848;
    }
</style>
